package com.example.myretrofit2.common;

import android.content.Context;

import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

public class ImageLoaderManager {
    public static ImageLoaderManager mInstance;
    private ImageLoaderConfiguration myconfig(Context context){
        ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(context)
                .memoryCacheExtraOptions(480,800)
                .memoryCache(new LruMemoryCache(2*1024*10024))
                .diskCacheSize(50*1024*1024)
                .diskCacheFileCount(100)
                .diskCacheFileNameGenerator(new HashCodeFileNameGenerator())
                .diskCacheExtraOptions(480,800,null)
                .threadPoolSize(3)
                .threadPriority(Thread.NORM_PRIORITY-2)
                .denyCacheImageMultipleSizesInMemory()
                .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
                .writeDebugLogs()
                .build();
        return configuration;
    }
        public static ImageLoaderManager getInstance(){
            if(mInstance == null){
                mInstance = new ImageLoaderManager();
            }
            return mInstance;
        }

    public ImageLoaderManager() {
        if(mInstance == null){
            ImageLoader.getInstance().init(myconfig(MyApplication.getContext()));
        }
    }
}
